package cc.lj.internal.api.merchant.api.fallbackfactory;

import cc.lj.internal.api.merchant.api.PropertyRelationFeignService;
import cc.lj.internal.api.merchant.dto.PropertyRelatonApiDTO;
import cc.lj.internal.api.merchant.query.PropertyRelationApiQuery;
import cc.lj.internal.core.http.HttpResult;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 物业资源展位区域fegin回退处理，可以打印出具体回退原因
 * 注意：只有配置文件中开启hystrix (feign.hystrix.enabled=true),该配置才会起作用
 * @author liangxifeng
 * @date 2022-01-05
 */
@Component
@Slf4j
public class PropertyRelationFeignServiceFallbackFactory implements FallbackFactory<PropertyRelationFeignService>  {
    @Override
    public PropertyRelationFeignService create(Throwable throwable) {
        log.error("feign--请求展位区域列表失败,原因:" + throwable.getMessage());
        return new PropertyRelationFeignService() {
            /**
             * 查询某个区域列表
             * @param propertyRelationQuery
             * @return展位区域list
             */
            @Override
            public HttpResult<List<PropertyRelatonApiDTO>> showAreaList(PropertyRelationApiQuery propertyRelationQuery) {
                return new HttpResult<>(HttpResult.SERVICE_FUSING.getCode(), HttpResult.SERVICE_FUSING.getMessage()+":"+throwable.getMessage());
            }
        };
    }
}
